home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / lzwlib / lzw.h < prev    next >
Text File  |  1992-03-16  |  7KB  |  193 lines

  1. // LZW.H - Header file for LZW library
  2. //
  3. // LZW Options
  4. //
  5. #define PATHNAMES       0x00000001L     // Store pathnames
  6.  
  7. // UNLZW Options
  8. //
  9. #define EXTRACT         0x00000001L     // Extract from .LZW file
  10. #define VIEW            0x00000002L     // View only 
  11. #define CREATEDIRS      0x00000004L     // Create held directories
  12. #define NOOVERWRITE     0x00000008L     // NO overwrite existing files
  13.  
  14. // LZW ENCODE/DECODE DEFINES
  15. //
  16. #define N               4096                  // buffer size
  17. #define F               60                    // lookahead buffer size
  18. #define THRESHOLD       2
  19. #define NIL             N                     // leaf of tree
  20. #define T               (N_CHAR * 2 - 1)      // size of table
  21. #define R               (T - 1)               // position of root
  22. #define MAX_FREQ        0x8000                // updates tree when the
  23. #define N_CHAR          (256 - THRESHOLD + F) // kinds of characters
  24.                                               // (character code = 0..
  25.                                               // N_CHAR-1) root frequency
  26.                                               // comes to this value.
  27.  
  28. // LZW ENCODE/DECODE TYPEDEF
  29. typedef unsigned char UCHAR;
  30.  
  31.  
  32. // FILE HEADER STRUCTURE.  FIRST ITEM READ WHEN .LZW FILE IS OPENED
  33. //
  34. typedef struct
  35. {
  36.   char lzwid;
  37.   unsigned int num_files;
  38.   unsigned long linkpos;
  39. }LZW_HDR;
  40.  
  41. // FIELDS FOR LINKED LIST
  42. //
  43. typedef struct
  44. {
  45.   char marked;
  46.   char path[60];
  47.   char name[13];
  48.   unsigned long filepos;
  49.   unsigned long size;
  50.   unsigned long length;
  51.   unsigned int date;
  52.   unsigned int time;
  53. }FIELDS,*FIELDSPTR;
  54.  
  55. // STRUCTURE OF LINKED LIST ITEMS
  56. //
  57. struct db_type
  58. {
  59.   FIELDSPTR fields;
  60.   struct db_type *prior;
  61.   struct db_type *next;
  62. };
  63.  
  64.  
  65. // GLOBALS
  66. //
  67. LZW_HDR lzw_hdr;
  68. struct db_type *first, *last, *cur_rec;
  69.  
  70. // LZW ENCODE/DECODE STUFF
  71. //
  72. // ===== MUST BE REINITIALIZED BEFORE ANY CALLS TO ENCODE OR DECODE
  73. //
  74. unsigned long  textsize = 0, codesize = 0, printcount = 0;
  75. unsigned getbuf = 0;
  76. UCHAR getlen = 0;
  77. unsigned putbuf = 0;
  78. UCHAR putlen = 0;
  79.  
  80. unsigned char  text_buf[N + F - 1];
  81. int            match_position, match_length, lson[N + 1];
  82. int            rson[N+257], dad[N+1];
  83. unsigned freq[T+1];     /* frequency table */
  84. int prnt[T + N_CHAR];   /* pointers to parent nodes, except for the */
  85.                         /* elements [T..T + N_CHAR - 1] which are used to get */
  86.                         /* the positions of leaves corresponding to the codes. */
  87. int son[T];             /* pointers to child nodes (son[], son[] + 1) */
  88. unsigned code, len;
  89.  
  90. // ===== FOR ENCODING =========================================
  91. //
  92. UCHAR p_len[64] = {
  93.   0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05,
  94.   0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06,
  95.   0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  96.   0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  97.   0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  98.   0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  99.   0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
  100.   0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08
  101. };
  102.   
  103. UCHAR p_code[64] = {
  104.   0x00, 0x20, 0x30, 0x40, 0x50, 0x58, 0x60, 0x68,
  105.   0x70, 0x78, 0x80, 0x88, 0x90, 0x94, 0x98, 0x9C,
  106.   0xA0, 0xA4, 0xA8, 0xAC, 0xB0, 0xB4, 0xB8, 0xBC,
  107.   0xC0, 0xC2, 0xC4, 0xC6, 0xC8, 0xCA, 0xCC, 0xCE,
  108.   0xD0, 0xD2, 0xD4, 0xD6, 0xD8, 0xDA, 0xDC, 0xDE,
  109.   0xE0, 0xE2, 0xE4, 0xE6, 0xE8, 0xEA, 0xEC, 0xEE,
  110.   0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
  111.   0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
  112. };
  113.   
  114. // ===== for decoding =========================================
  115. //
  116. UCHAR d_code[256] = {
  117.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  118.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  119.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  120.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  121.   0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  122.   0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  123.   0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
  124.   0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
  125.   0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
  126.   0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
  127.   0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  128.   0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
  129.   0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  130.   0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  131.   0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
  132.   0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
  133.   0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A,
  134.   0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B,
  135.   0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D,
  136.   0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F,
  137.   0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11,
  138.   0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13,
  139.   0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15,
  140.   0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x17,
  141.   0x18, 0x18, 0x19, 0x19, 0x1A, 0x1A, 0x1B, 0x1B,
  142.   0x1C, 0x1C, 0x1D, 0x1D, 0x1E, 0x1E, 0x1F, 0x1F,
  143.   0x20, 0x20, 0x21, 0x21, 0x22, 0x22, 0x23, 0x23,
  144.   0x24, 0x24, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27,
  145.   0x28, 0x28, 0x29, 0x29, 0x2A, 0x2A, 0x2B, 0x2B,
  146.   0x2C, 0x2C, 0x2D, 0x2D, 0x2E, 0x2E, 0x2F, 0x2F,
  147.   0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  148.   0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
  149. };
  150.   
  151. UCHAR d_len[256] = {
  152.   0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
  153.   0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
  154.   0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
  155.   0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
  156.   0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  157.   0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  158.   0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  159.   0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  160.   0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  161.   0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  162.   0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
  163.   0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
  164.   0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
  165.   0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
  166.   0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
  167.   0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
  168.   0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
  169.   0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
  170.   0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  171.   0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  172.   0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  173.   0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  174.   0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  175.   0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  176.   0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  177.   0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  178.   0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  179.   0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  180.   0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  181.   0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  182.   0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
  183.   0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
  184. };
  185.  
  186. // FUNCTION PROTOTYPES
  187. //
  188. void lzw_init(void);
  189. void lzw_deinit(void);
  190. int lzw(char *,unsigned long,char *);
  191. int unlzw(char *,unsigned long,char *);
  192. int lzwpurge(char *,char *);
  193.